Day 16 - Regular expressions -

Multiple matches

Solutions to exercises

Exercise 16.01

Match all the occurrences of exactly three digits in the file examples.txt

Solution

$ grep -E "[0-9]{3}" examples.txt

Police 101

007

Cyborg 009

Go back to the exercise

Exercise 16.02

The log file simple.log contains the status of HTTP responses, which is a three digit number preceded

and followed by a space. HTTP statuses are categorised according to the initial digit and 4xx

responses (that is 400, 401, 402, and so on) are considered resource errors. Count how many HTTP

4xx responses are in the file for each type of error.

Solution

$ grep -Eo " 4[0-9]{2} " simple.log | sort | uniq -c

2

403

213

404

2

416

1

481

Go back to the exercise